package cn.bqjr.eily.utils;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ResourceBundleMessageSource;

import java.util.Locale;

/**
 * Created by hp on 2017/6/19.
 */
public class I18nUtils {

    private static MessageSource messageSource = null;

    public static MessageSource getMsgSource() {
        if (messageSource == null) {
            return SpringContextUtils.getBean(ResourceBundleMessageSource.class);
        }
        return messageSource;
    }

    public static String getMsg(String key) {
        return getMsg(key, LocaleContextHolder.getLocale());
    }

    public static String getMsg(String key, Locale locale) {
        return getMsgSource().getMessage(key, null, locale);
    }
}
